package yinghan;
import java.util.Scanner;
public class RegisAndLogin extends Account{
    //boolean用于判断是否注册成功
    public boolean regis(Account account,Scanner sc){
        System.out.println("请输入整数型的注册账户：");
        int uname=sc.nextInt();
        for(int i=0;i<3;i++){
            System.out.println("请输入整数型的账户密码：");
            int pword=sc.nextInt();
            System.out.println("请二次输入密码：");
            int pword2=sc.nextInt();
            if(pword==pword2){
                //成功
                account.setPassword(pword);
                break;
            }else{
                System.out.println("两次输入密码不正确！");
                if(i==2){
                    return false;
                }
            }
        }
        System.out.println("请输入用户名：");
        String name=sc.next();
        System.out.println("请输入年龄：");
        int age=sc.nextInt();
        account.setMoney(10000);
        account.setUsername(uname);
        account.setName(name);
        account.setAge(age);
        return true;

    }
    //boolean用于判断是否登陆成功
    public boolean login(Account account,Scanner sc){
        System.out.println("请输入账户名:");
        for(int i=0;i<3;i++){
            int uname=sc.nextInt();
            if(uname==account.getUsername()){
                //账号正确
                break;
            }else{
                System.out.println("不存在此账户!请重新输入:");
                if(i==2){
                    return false;
                }
            }
        }

        System.out.println("请输入账户密码:");
        for(int j=0;j<3;j++){
            int pword=sc.nextInt();
            if(pword==account.getPassword()){
                //密码正确
                break;
            }else{
                System.out.println("密码有误!请重新输入:");
                if(j==2){
                    return false;
                }
            }
        }

        return true;

    }

}